package openjdk.future;

import java.util.concurrent.*;

/**
 * Created by boot on 1/11/16.
 */
public class CallBack {
    public static void main(String[] args) {
        ExecutorService svc = Executors.newCachedThreadPool();

        FutureTask<String> task = new FutureTask<String>(new Callable<String>() {
            public String call() throws Exception {
                try {
                    Thread.sleep(5 * 1000);
                    return "Hello world";
                } catch (Exception e) {
                    throw new Exception("Callable terminated with Execption");
                }
            }
        });

        svc.execute(task);
        System.out.println("after the execute(task) line.");

        try {
            System.out.println("before get the return value.");
            System.out.println(task.get());
            System.out.println("end of the get method");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
